(function () {
    window.amapdirll = function (id, obj) {
        return new Amapdirll(id, obj)
    }
    function Amapdirll(id, obj) {
        this.parms = {
            //多边形配置
            PolygonOptions: {
                normal: {
                    strokeColor: "#1791fc", //线颜色
                    strokeOpacity: 0.5, //线透明度
                    strokeWeight: 2,    //线宽
                    fillColor: "#1791fc", //填充色
                    fillOpacity: 0.1,//填充透明度,
                },
                hover: {
                    strokeColor: "#1791fc", //线颜色
                    strokeOpacity: 0.8, //线透明度
                    strokeWeight: 3,    //线宽
                    fillColor: "#1791fc", //填充色
                    fillOpacity: 0.2//填充透明度
                },
                active: {
                    strokeColor: "#1791fc", //线颜色
                    strokeOpacity: 0.8, //线透明度
                    strokeWeight: 3,    //线宽
                    fillColor: "#1791fc", //填充色
                    fillOpacity: 0.8//填充透明度
                }
            },
            carousel:false,//控制多边形是否轮播
            mapStyle:'amap://styles/ede3c9f2c29cd2f4d933a60e4c17c6b5',
            styleClass:0,
            center:[102.160304, 26.848149],
            DrawGridText:true,
            DrawGridRelative:true,//true 关
            isCustom:false,//窗口是否完全自定义
            mappolygons:[],
        },
        this.heatmap=null;//热地图
        this.map = '';
        this.id = id;
        this.polygon = [];//定义多边形
        this.text = [];//多边形title
        this.textFlag = [];//添加标注
        this.cluster = null;//添加聚合
        this.position_marker = null;//位置maker
        this.infoWindow = null;
        this.overlays=[];//绘制图形
        this.mouseTool=null;//鼠标绘制插件
        this.Icons = ['status01.png', 'status02.png', 'status03.png'];
        this.textFlagIco = [
            ['qsd0.png', 'qsd1.png', 'qsd2.png'],
            ['swxhs0.png', 'swxhs1.png', 'swxhs2.png'],
            ['xfsh0.png', 'xfsh1.png', 'xfsh2.png'],
        ]
        this.AutoPoint = [];//自定义图标点
        this.markePoint=[];
        this.init(obj);
        this.setIntervalParm = {
            i: 0,
            server_id: null,
        }
        this.drawGrid3DColor=['rgba(0, 94, 255, 0.3)','rgba(0,124,237,0.4)','rgba(0,158,235,0.5)','rgba(0,182,229,0.2)','rgba(0,211,215,0.3)'];
        this.districtExplorer=null;
        this.geocoder = null;
        this.polylineEditor=null;//编辑折线
        this.settime=null//折线划过定时显示
        this.currentPolylineIndex=0;//当前编辑的折现

    }
    Amapdirll.prototype = {
        //初始化
        init(obj) {
            obj.PolygonOptions = obj.PolygonOptions ? obj.PolygonOptions : this.parms.PolygonOptions;
            Object.assign(this.parms, obj);
            document.getElementById(this.id).setAttribute('No', this.parms.styleClass);
            this.createMap();

        },
        //创建地图
        createMap() {
            let _this = this;
            if (!document.getElementById(this.id)) return false;
            this.map = new AMap.Map(this.id, {
                resizeEnable: true,
                rotateEnable: false,
                pitchEnable: true,
                showLabel: true, //不显示地图文字标记
                // pitch:70,
                rotation:0,
                viewMode: '2D',//开启3D视图,默认为关闭
                expandZoomRange: true,
                zooms: [4, 20],
                zoom:4,
                center: _this.parms.center,//初始化地图中心点,
                mapStyle: _this.parms.mapStyle,
                isHotspot:true,
                skyColor:'rgba(43,80,191,.6)',

            });
            _this.parms.PolygonOptions.normal.map = _this.map;
            // this.map.on("complete", function(){
            //     地图加载完成
            // });

        },
        complete(callback=()=>{}){
            // this.isSearch();
            let _this = this;
            _this.map.on("complete", function () {
                callback(this)
                // _this.monitorMapZoom();
            });
        },
        //
        setGeocoder(){
            this.geocoder= new AMap.Geocoder({
                city: "010", //城市设为北京，默认：“全国”
            });
        },
        geoCode(address,callback=()=>{}){
            if(!this.geocoder) this.setGeocoder();
            this.geocoder.getLocation(address, function(status, result) {
                if (status === 'complete'&&result.geocodes.length) {
                    let lnglat = result.geocodes[0].location;
                    this.map.setCenter(lnglat);
                    callback();
                    this.map.setFitView();
                }else{
                    console.log('根据地址查询位置失败');
                }
            });
        },
      // 开启绘图插件
      startCanvs(callback=()=>{}){
        let _this=this;
        if(!this.mouseTool){
          this.mouseTool = new AMap.MouseTool(this.map);
        }
        this.mouseTool.on('draw',function(e){
          console.log(e.obj.getPath(),'eee');
          _this.overlays.push(e.obj);
          callback(e.obj.getPath())
          _this.toolClose();
          _this.drawAreaLine([{path:_this.formatPostion(e.obj.getPath())}]);
        })
      },
      formatPostion(arr=[]){//格式化
         let path=[];
         arr.map(item=>{
           path.push(new AMap.LngLat(item.lng,item.lat))
         })
        return path;
      },
      toolClose(){
        this.mouseTool.close(true)//关闭，并清除覆盖物
      },
      draw(type,callback=()=>{}){//设置绘制的配置
        this.startCanvs(callback);
        this.clearDraw();
        switch(type){
          case 'marker':{
            this.mouseTool.marker({
              //同Marker的Option设置
            });
            break;
          }
          case 'polyline':{
            this.mouseTool.polyline({
              strokeColor:'#80d8ff'
              //同Polyline的Option设置
            });
            break;
          }
          case 'polygon':{
            this.mouseTool.polygon({
              fillColor:'#00b0ff',
              strokeColor:'#80d8ff'
              //同Polygon的Option设置
            });
            break;
          }
          case 'rectangle':{
            this.mouseTool.rectangle({
              fillColor:'#00b0ff',
              strokeColor:'#80d8ff'
              //同Polygon的Option设置
            });
            break;
          }
          case 'circle':{
            this.mouseTool.circle({
              fillColor:'#00b0ff',
              strokeColor:'#80d8ff'
              //同Circle的Option设置
            });
            break;
          }
        }
      },
      //清除插件绘图
      clearDraw(){
        this.map.remove(this.overlays)
        this.overlays = [];
      },
      drawGrid3D(arr,colors){
            console.log(arr,'arrr')
            let _this=this;
            this.drawGrid3dInit();
            arr.map((item,index)=>{
            //    console.log(this.drawGrid3DColor[index%5],'rrrrr');
               this.drawGrid3DStartDraw(this.drawGird3Dformat(item),this.drawGrid3DColor[index%5]);
            })
            _this.map.setFitView();

        },
        drawGrid3dInit(){
            // 设置光照
            let _this=this;
            this.map.AmbientLight = new AMap.Lights.AmbientLight([1, 1, 1], 0.5);
            this.map.DirectionLight = new AMap.Lights.DirectionLight([0, 0, 1], [1, 1, 1], 1);
            this.object3Dlayer = new AMap.Object3DLayer();
            this.map.add(this.object3Dlayer);
            this.map.on('mousemove', function (ev) {
                let pixel = ev.pixel;
                let px = new AMap.Pixel(pixel.x, pixel.y);
                let obj = _this.map.getObject3DByContainerPos(px, [_this.object3Dlayer], false) || {};
                if(obj&&obj.object){
                    obj.object.color="green"
                    console.log(obj.object.text,'-');
                }

            })

        },
        drawGird3Dformat(arr=[]){
            let mm=[];
            arr.map(function(item,index){
                mm.push(new AMap.LngLat(item.lng,item.lat));
            });
            return mm;
        },
        drawGrid3DStartDraw(mm,color){
            let _color=color||'#008aff';
            let prism = new AMap.Object3D.Prism({
                path: mm,
                height: 8000,
                color:_color
            });
            prism.transparent = true;
            // prism.text=_text;
            this.object3Dlayer.add(prism);

        },
        closePolylineEditor(callback){
            this.polylineEditor&&this.polylineEditor.close();
        },
        PolylineEditor(id,callback){
          if(id){//获取要编辑的折现
              this.currentPolylineIndex=this.polygon.findIndex(o=>_.get(o,'w.id')==id)!=-1?this.polygon.findIndex(o=>_.get(o,'w.id')==id):0;
          }
          if(!this.polylineEditor){
              this.getpolylineEditor(callback);
          }else{
              this.setploylineEditor(callback)
          }

        },
        getpolylineEditor(callback){
            this.map.plugin(["AMap.PolyEditor"],()=>{
                this.setploylineEditor(callback)
            });
        },
        setploylineEditor(callback){
            this.polylineEditor = new AMap.PolyEditor(this.map,this.polygon[this.currentPolylineIndex]);
            this.setCenter({
                gps_lat:_.get(this.polygon[this.currentPolylineIndex],'w.path.0.lat'),
                gps_lng:_.get(this.polygon[this.currentPolylineIndex],'w.path.0.lng'),
            })
            // 开启编辑模式
            this.polylineEditor.open();
            this.polylineEditor.on('end',({type,target})=>{
                callback({type,target});
            })
        },
      //绘制护栏
      drawAreaLine(arr, callback=()=>{},callback02=()=>{},callback03=()=>{}) {
        this.clearAll();
        let polygon = [];
        let options = {
          strokeWeight:4, //设置多边形边线线粗
          strokeOpacity:1, //设置多边形边线透明度0-1
          StrokeStyle: "solid", //设置多边形边线样式为实线或虚线，取值 solid 或 dashed
          strokeColor:"rgba(53, 221, 249, 0.6)", //设置多边形边线颜色,
          strokeDasharray:[10,2],
          geodesic:true,
          strokeStyle:'dashed',
        }
        arr.map((item,i)=>{
           // console.log(item,'item.path');
          polygon[i] = new AMap.Polyline({
            path:item.path,
            ...options,
              id:item.id||''+(new Date()).getTime()
          });
          //添加双击事件
          polygon[i].on('dblclick', function () {
            callback(arr[i])
          });
          //添加滑动事件
          polygon[i].on('mouseover', function () {
              this.setOptions({
                  strokeWeight:8, //设置多边形边线线粗
                  strokeOpacity:1, //设置多边形边线透明度0-1
                  StrokeStyle: "solid", //设置多边形边线样式为实线或虚线，取值 solid 或 dashed
                  strokeColor:"rgba(53, 221, 249, 1)", //设置多边形边线颜色,
              })

             // console.log(i,arr[i],'我是当前的滑动事件！')
              clearTimeout(this.settime);
              this.settime= setTimeout(()=>{
                  callback('mouseover',arr[i])
              },2000)

          });

          //添加移除事件
          polygon[i].on('mouseout', function () {
              this.setOptions({
                  strokeWeight:4, //设置多边形边线线粗
                  strokeColor:"rgba(53, 221, 249, 0.6)", //设置多边形边线颜色,
              })
              clearTimeout(this.settime);
              callback('mouseout',{})

          });
            polygon[i].setMap(this.map);//地图上添加折线
        });
        // this.map.add(polygon);
        this.polygon = polygon;
        callback02();
        // this.map.setFitView();
        //   this.setCenter({
        //       gps_lat:_.get(this.polygon[this.currentPolylineIndex],'w.path.0.lat'),
        //       gps_lng:_.get(this.polygon[this.currentPolylineIndex],'w.path.0.lng'),
        //   })
        this.map.setCenter(_.get(arr,this.currentPolylineIndex+'.path.0'));
        callback03()
      },
        //绘制网格
        drawAreaGrid(arr, callback=()=>{},callback02=()=>{},callback03=()=>{}) {
            this.clearAll();
            let polygon = [];
            let options = {
                fillColor:"rgba(0,166,255,0.01)",
                strokeWeight:1, //设置多边形边线线粗
                strokeOpacity:1, //设置多边形边线透明度0-1
                StrokeStyle: "solid", //设置多边形边线样式为实线或虚线，取值 solid 或 dashed
                strokeColor:"rgba(0,135,255,0.2)", //设置多边形边线颜色,
                fillOpacity:.1
            }
            arr.map((item,i)=>{
                // console.log(item.path,'item.path');
                polygon[i] = new AMap.Polygon({
                    path:item.path,
                    ...options
                });
                polygon[i].region_code=item.region_code;
                //添加双击事件
                polygon[i].on('dblclick', function () {
                    callback(arr[i])
                });
                //添加滑动事件
                polygon[i].on('mouseover', function () {
                    polygon.map(s=>{
                        console.log(this.region_code,'this.region_code',s.region_code)
                        if(s.region_code==this.region_code){
                            this.setOptions({
                                fillColor:"rgba(0,135,255,.2)"
                            })
                        }
                    })

                });
                //添加移除事件
                polygon[i].on('mouseout', function () {
                    //
                    polygon.map(s=>{

                        this.setOptions({
                            fillColor:"rgba(0,135,255,.01)"
                        })
                    })
                });
            });
            this.map.add(polygon);
            this.polygon = polygon;
            callback02();
            this.map.setFitView();
            setTimeout(()=>{
                this.map.zoomOut();
                // debugger;
            },500)
        },
        //绘制网格
        drawGrid(arr, callback=()=>{},callback02=()=>{},callback03=()=>{}) {
            let _this = this;
            let fun = callback;
            let fun2=callback02;
            _this.marker = [];
            _this.carousel().clearIntervalFun();
            if(_this.parms.DrawGridRelative){
                _this.clearAll();
            }
            if (arr.constructor == Array && arr.length > 0) {
                arr = this.dataformat(arr);
                let _legth = arr.length;
                let polygon = [], text = [], normalStyle = (new Array(_legth)).fill({}), activeStyle = (new Array(_legth)).fill({}), hoverStyle = (new Array(_legth)).fill({});
                for (let i = 0; i < _legth; i++) {
                    Object.assign(normalStyle[i], _this.parms.PolygonOptions.normal);
                    Object.assign(activeStyle[i], _this.parms.PolygonOptions.active);
                    Object.assign(hoverStyle[i], _this.parms.PolygonOptions.hover);
                    if (arr[i].PolygonOptions) {
                        if (arr[i].PolygonOptions.normal) Object.assign(normalStyle[i], arr[i].PolygonOptions.normal);
                        if (arr[i].PolygonOptions.active) Object.assign(activeStyle[i], arr[i].PolygonOptions.active);
                        if (arr[i].PolygonOptions.hover) Object.assign(hoverStyle[i], arr[i].PolygonOptions.hover);
                    }

                    if(arr[i].noPath) {
                      continue ;
                    }

                    if (arr[i].path[0]&& typeof arr[i].path[0][0] == 'number') {
                        normalStyle[i].path = arr[i].path;
                        polygon[i] = new AMap.Polygon(normalStyle[i]);
                        delete normalStyle[i].path;
                        polygon[i].autoPolygonOptions = {
                            normal: Object.assign([], normalStyle[i]),
                            active: Object.assign([], activeStyle[i]),
                            hover: Object.assign([], hoverStyle[i]),
                        }
                        polygon[i].on('dblclick', function () {
                            _this.changeGridStyles(i, 'active');
                            fun(i)
                        });
                        polygon[i].on('mouseover', function () {
                            _this.changeGridStyles(i, 'hover');
                            //fun(i)
                        });
                        polygon[i].on('mouseout', function () {
                            _this.changeGridStyles(i, 'normal');
                            // fun(i)
                        });
                        // if(arr[i].showLabel){
                        //
                        // }
                        if(_this.parms.DrawGridText){

                            _this.drawText(arr[i], i, fun2);
                        }
                    }
                    else {
                        //二位数组数据处理
                        let polygons = []
                        arr[i].path.map((item) => {

                            normalStyle[i].path = item;
                            let poly = new AMap.Polygon(normalStyle[i]);

                            delete normalStyle[i].path;

                            poly.autoPolygonOptions = {
                                normal: Object.assign([], normalStyle[i]),
                                active: Object.assign([], activeStyle[i]),
                                hover: Object.assign([], hoverStyle[i]),
                            }
                            polygons.push(poly)

                        })

                        polygon[i] = polygons

                        polygons.map(item => {
                            item.on('dblclick', function () {

                                _this.changeGridStyles(i, 'active');
                                fun(i)
                            });
                            item.on('mouseover', function () {

                                _this.changeGridStyles(i, 'hover');

                            });
                            item.on('mouseout', function () {
                                _this.changeGridStyles(i, 'normal');
                            });

                        })
                        if(_this.parms.DrawGridText){
                            _this.drawText(arr[i], i, fun2);
                        }
                        // console.log(arr[i].path[0][0], '2222222222');

                    }

                }
                _this.polygon = polygon;
                if (_this.parms.carousel) {
                    _this.carousel().setIntervalFun();
                }
                // debugger;

                callback03();
            } else {
                console.log('传入的数据类型有问题')
            }
        },
        //影藏区域
        hideGrid(){
            // debugger;
            if(this.polygon){
                for(let i=0;i<this.polygon.length;i++){

                    for(let j=0;j<this.polygon[i].length;j++){
                        this.polygon[i][j].hide();
                    }
                    // if(this.polygon[i].constructor === Array&&this.polygon[i][0]){
                    //     this.polygon[i][0].hide();
                    // }else if(this.polygon[i]&&this.polygon[i].hide){
                    //     this.polygon[i].hide();
                    // }
                }
            }
        },
        removeAllOverlay(){
            // 清除地图上所有添加的覆盖物
            this.map.clearMap();
        },
        showGrid(){
            if(this.polygon){
                // for(let i=0;i<this.polygon.length;i++){
                //     // console.log(this.polygon[i][0],'this.polygon[i].hide');
                //     // console.log(this.polygon[i],'this.polygon[i].hide2222');
                //     if(this.polygon[i].constructor === Array&&this.polygon[i][0]){
                //         this.polygon[i][0].show();
                //     }else if(this.polygon[i]&&this.polygon[i].show){
                //         this.polygon[i].show();
                //     }
                // }
                if(this.polygon){
                    for(let i=0;i<this.polygon.length;i++){

                        for(let j=0;j<this.polygon[i].length;j++){
                            this.polygon[i][j].show();
                        }
                    }
                }
            }
        },

        // 修改网格样式
        changeGridStyles: function (i, type, styles) {
            let _this = this, obj = _this.polygon[i];
            // console.log(typeof obj, obj instanceof Array);

            if (obj instanceof Array) {
                obj.map(item => {

                    type = item.autoPolygonOptions[type] ? type : 'normal';
                    styles = styles || item.autoPolygonOptions[type];
                    item.setOptions(styles);

                })


            } else {
                type = obj.autoPolygonOptions[type] ? type : 'normal';
                styles = styles || obj.autoPolygonOptions[type];
                _this.polygon.map(function (item, index) {
                    // console.log(item);
                    if (item instanceof Array) {

                    }
                    else {
                        if (index == i) {
                            item.setOptions(styles);
                        } else {
                            item.setOptions(item.autoPolygonOptions.normal);
                        }
                    }

                })

            }

        },


         //绘制多个标点
         drawPoints(arr,fun=()=>{},callback=()=>{}){
            let _this=this;
            this.clearPointMarker();
            arr.map((item,index)=>{
                this.drawPoint(item,index,fun,callback)
            })
        },
         //绘制一个标点
         drawPoint(obj={}, i=0, fun,callback) {
            let _this = this;
            let point;
            if (!this.checkLng(obj.lng) || !this.checkLat(obj.lat))  return false;
            point = new AMap.LngLat(obj.lng, obj.lat);
            // let ico='./img/qsd0.png';
            let ico = require('../img/qsd0.png');
            let className=obj.status==1?'':'map-flag-box-normal';
            let noramlOffset=obj.status==1?new AMap.Pixel(-29,-119):new AMap.Pixel(-14,-64);
            let extData={
                noramlOffset:noramlOffset,
                hoverOffset: new AMap.Pixel(-29,-119),
                normalContent:'<div id="'+obj.id+'" class="'+className+' map-flag-box status'+obj.status+'"><div class="map-flag-info"><div class="map-flag-txt"><div class="window-left-ico"></div><div class="window-middle-ico"></div><div class="window-con-info"><div class="window-con-tit"><span>'+obj.name+'</span></div><ul class="window-con-list"><li><label>联系地址：</label>'+obj.address+'<li><li><label>消防责任人：</label>'+obj.safety_person+'<li></ul></div></div><div class="unit-ico icon font_family icon-'+obj.type+' status'+obj.status+'"></div></div><div class="map-zt"><span class="zt-list01 zt-list"></span><span class="zt-list02 zt-list"></span><span class="zt-list03 zt-list"></span><span class="zt-list04 zt-list"></span></div><div class="map-flag-yy"></div></div>',
                hoverContent:'<div id="'+obj.id+'" class="map-flag-box status'+obj.status+'"><div class="map-flag-info"><div class="map-flag-txt"><div class="window-left-ico"></div><div class="window-middle-ico"></div><div class="window-con-info"><div class="window-con-tit"><span>'+obj.name+'</span></div><ul class="window-con-list"><li><label>联系地址：</label>'+obj.address+'<li><li><label>消防责任人：</label>'+obj.safety_person+'<li></ul></div></div><div class="unit-ico icon font_family icon-'+obj.type+' status'+obj.status+'"></div></div><div class="map-zt"><span class="zt-list01 zt-list"></span><span class="zt-list02 zt-list"></span><span class="zt-list03 zt-list"></span><span class="zt-list04 zt-list"></span></div><div class="map-flag-yy"></div></div>',
                obj:obj,
            }
            let marker = new AMap.Marker({
                position:point,
                content:extData.normalContent, //设置文本标注内容,
                icon:ico,
                size:[1,1],
                offset:extData.noramlOffset,
                zIndex:200,
                extData:extData,
            });
            marker.setMap(_this.map);
            _this.markePoint.push(marker);
            marker.on('click', function () {
                fun(obj);
            });
            marker.on('mouseover', function () {
                this.setOffset( this.getExtData().hoverOffset)
                this.setContent(this.getExtData().hoverContent);

            });
            marker.on('mouseout', function () {
                this.setOffset( this.getExtData().noramlOffset);
                this.setContent(this.getExtData().normalContent);
            });
            // _this.map.setFitView();
            callback();
        },
        //隐藏点标记
        hideMarker(){
            this.markePoint.map((item)=>{
                item.hide();
            })
        },
        showMarker(){
            this.markePoint.map((item)=>{
                item.show();
            })
        },
        clearPointMarker(){
            if(!this.markePoint) return false;
            this.markePoint.map((item)=>{
                this.map.remove(item)
            })
        },

        //删除3d网格
        delete3dGrid(){
            if(this.object3Dlayer&&this.object3Dlayer.clear){
                this.object3Dlayer.clear();
            }
        },
        //绘制火警点
        //绘制一个标点
        drawAlarmPoint(obj,fun) {
            //  console.log(obj.type,'objtype');
            // debugger;
            let _this = this;
            let callback=fun||Function;
            let point;
            if (!this.checkLng(obj.lng) || !this.checkLat(obj.lat))  return false;
            point = new AMap.LngLat(obj.lng, obj.lat);
            let ico='./img/alarm.png';//静态页面时候
            // let ico = require('../img/alarm.png');
            let marker = new AMap.Marker({
                position:point,
                content: '<div id="'+obj.id+'" class="map-hotMassage"><div class="map-hotMassage-block"><div class="alram-ico"></div><div class="alarm-content"><div  class="alarm-content-detial"><div class="alarm-content-title">'+obj.text+'</div><div class="alarm-content-info"><div class="alarm-adress"><i class="iconfont iconweizhi"></i> '+obj.adress+'</div><div class="alarm-time"> <i class="iconfont iconshijian"></i> '+obj.time+'</div></div></div><div class="alarm-line"></div></div></div></div>', //设置文本标注内容,
                icon:ico,
                size:[1,1],
                offset: new AMap.Pixel(-73,-38),
                zIndex:200,
            });
            marker.setMap(_this.map);
            _this.alarm_marker.push(
                {
                    id:obj.id,
                    marker:marker
                }
            )
            _this.map.setFitView();
        },
        //隐藏火警
        hideAlarmMarker(){
            this.alarm_marker.map((item)=>{
                item.marker.hide();
            })
            // debugger;
        },
        //删除火警
        deletAlarmMarker(id){
            let _this=this;
            this.alarm_marker.map((item)=>{
                if(item.id==id){
                    _this.map.remove(item.marker);
                }
            })
            // debugger;
        },

         //展示火警
         showAlarmMarker(){
            this.alarm_marker.map((item)=>{
                item.marker.show();
            })
            // debugger;
        },
        //创建gps小车
        CreateGpsCar(obj,fun){
            // debugger;
            let _this = this;
            let callback=fun||Function;
            if (!this.checkLng(obj.lng) || !this.checkLat(obj.lat))  return false;
            this.GpsCar.map((item)=>{
                if(item.id==obj.id){
                    return false;
                }
            })
            let marker = new AMap.Marker({
                map: _this.map,
                position: [obj.lng,obj.lat],
                icon: "https://webapi.amap.com/images/car.png",
                offset: new AMap.Pixel(-26, -13),
                autoRotation: true,
                angle:-90,
                // animation:'AMAP_ANIMATION_DROP',
                // content:'<div class="gps-car-map" id="'+obj.id+'">'+obj.text+'</div>'
            });
            marker.setLabel({
                offset: new AMap.Pixel(20, 20),  //设置文本标注偏移量
                content: "<div class='gps-car-info'>"+obj.text+"</div>", //设置文本标注内容
            });
            marker.setMap(_this.map);
            this.GpsCar.push(
                {
                    id:obj.id,
                    marker:marker,
                }
            )

        },
        //删除gps 小车
        deletGpsCarMarker(id){
            let _this=this;
            this.GpsCar.map((item)=>{
                if(item.id==id){
                    _this.map.remove(item.marker);
                }
            })
            // debugger;
        },
        //修改小車的位置
        GpsCarMove(obj){
            let _this = this;
            // console.log(obj.id,'```````````````````');
            if (!this.checkLng(obj.lng) || !this.checkLat(obj.lat))  return false;
            // // debugger;
            // if("A20373"==obj.id){
            //     debugger;
            // }
            // if("A20387"==obj.id){
            //     debugger;
            // }
            this.GpsCar.map((item)=>{
                if(item.id==obj.id){
                   console.log(obj.lng,obj.lat,obj.id,'4444444444');
                    item.marker.moveTo(new AMap.LngLat(obj.lng,obj.lat),50);
                }
            })
        },
         //隐藏小车
         hideGpsCarMarker(){
            this.GpsCar.map((item)=>{
                item.marker.hide();
            })
            // debugger;
        },

         //展示小车
         showGpsCarMarker(){
            this.GpsCar.map((item)=>{
                item.marker.show();
            })
            // debugger;
        },

        //数据格式化
        dataformat(arr) {
            // console.log(arr,'dddddddd');

            arr.map(function (item,index) {
                let path = []
                // let border = item.border.split("|") ? item.border.split("|") : '';
                item.label = item.label.substring(0, 9);
                let _length =item.border? item.border.length:0;
                for (let i = 0; i < _length; i++) {
                    if (item.border[i].x) {
                        path.push([item.border[i].x, item.border[i].y])
                    }
                    else {

                        let p = []
                        item.border.map(item => {
                            let pp = []
                            item.map(it => {
                                pp.push([it.x, it.y])
                            })
                            p.push(pp)
                        })
                        path = p
                    }

                }


                item.path = path;
                if(!!!item.border) {
                  // arr.splice(index,1)
                  item.noPath = true;
                }
                // let path=[]
                // let border=item.border.split("|")?item.border.split("|"):'';
                // for(let i=0;_length=border.length,i<_length;i++){
                //     path.push(border[i].split(","));
                // }
                // item.path=path;
            })

            return arr;
        },



        //绘制文字
        drawText(obj, i, fun) {
            let _this = this;
            let point;


            if (obj.region_info&&this.checkLng(obj.region_info.lng) && this.checkLat(obj.region_info.lat)) {
                point = new AMap.LngLat(obj.region_info.lng, obj.region_info.lat);
            } else {
                // console.log(obj.path[0][0] instanceof Array);
                if(obj.path[0]){
                    let _point = _this.getAreaCenter(obj.path[0][0] instanceof Array ? obj.path[0] : obj.path);
                    // console.log(_point);

                    point = new AMap.LngLat(_point.lng, _point.lat);

                }
            }
            //let type=obj.type?obj.type:0;
            let scroe = obj.score;
            let no_scrore = '';
            let Icon, type=0;
            // if (!scroe && scroe != 0) {
            //     scroe = '尚无数据';
            //     no_scrore = 'no-score'
            //     type = 0
            // } else if (scroe >= 80) {
            //     type = 0;
            // } else if (scroe >= 50) {
            //     type = 1
            // } else {
            //     type = 2;
            // }
            if (!scroe ) {
                scroe = 0;
            }
            //因为暂时我们的数据大部分都是零 如果用红色的图标满屏都是红色，导致整体效果过分紧张，暂时定为文字红色作为区别；
            // Icon=this.Icons[type];
            Icon = this.Icons[0];
            // let ico='./img/'+Icon;//静态页面时候
            let ico = require('../img/' + Icon);//
            let _content='';
            // console.log(obj.straightPipe,'obj.straightPipe')
            if(obj.straightPipe&&obj.straightPipe>0){
                _content="<div class='marker-box' style='background:url("+ico+") no-repeat 0 0'><div class='  amap-type" + type + "'><div class='amap-text'>" + obj.label + "<span class='score "+no_scrore+"'><i class='g-normal g-position-relative'>" + scroe + "<span>家单位</span></i><i class='g-normal g-position-relative'>/" + obj.straightPipe + "<span>家直管</span></i></span></div></div></div>"; //设置文本标注内容,
            }else{
                _content="<div class='marker-box' style='background:url("+ico+") no-repeat 0 0'><div class='  amap-type" + type + "'><div class='amap-text'>" + obj.label + "<span class='score "+no_scrore+"'><i class='g-normal g-position-relative'>" + scroe + "<span>家单位</span></i></span></div></div></div>"; //设置文本标注内容,

            }
            let marker = new AMap.Marker({
                position:point,
                content: _content,
                icon:ico,
                size:[161,148],
                offset: new AMap.Pixel(0,-148),
                zIndex:200,
            });
            marker.setMap(_this.map);
            // marker.labelContent = {
            //     normal: "<div  class='  amap-type" + type + "'><div class='amap-text'>" + obj.label + "<span class='score "+no_scrore+"'>" + scroe + "</span></div></div>", //设置文本标注内容
            //     active: "<div class=' hover amap-type" + type + "'><div class='amap-text'>" + obj.label + "<span class='score  "+no_scrore+"'>" + scroe + "</span></div></div>", //设置文本标注内容
            //     hover: "<div class=' active amap-type" + type + "'><div class='amap-text'>" + obj.label + "<span class='score  "+no_scrore+"'>" + scroe + "</span></div></div>", //设置文本标注内容
            // }
            // marker.setLabel({
            //     offset: new AMap.Pixel(0,0),  //设置文本标注偏移量
            //     content: marker.labelContent.normal, //设置文本标注内容
            //     direction: 'left', //设置文本标注方位,
            // });
            _this.marker.push(marker);
            // if (obj.showLabel) {
            //     marker.show();
            // } else {
            //     marker.hide();
            // }
            marker.on('click', function () {
                if (_this.parms.carousel) _this.carousel().clearIntervalFun();
                //_this.changeGridStyles(i,'active');
                // _this.changeMarker(i, 'active')
                // debugger;
                fun(i);
            });
            marker.on('mouseover', function () {
                if (_this.parms.carousel) _this.carousel().clearIntervalFun();
                //_this.changeGridStyles(i,'hover');
                // _this.changeMarker(i, 'hover')

            });
            marker.on('mouseout', function () {
                // if (_this.parms.carousel) _this.carousel().setIntervalFun();
                // _this.changeMarker(i, 'normal')
            });
        },
        //隐藏绘制文字
        hidedrawText() {
            let _this = this;
            if (!_this.marker || _this.marker.length == 0) return false;
            _this.marker.map(function (item) {
                item.hide();
            })
        },
        //显示绘制文字
        showdrawText() {
            let _this = this;
            if (!_this.marker || _this.marker.length == 0) return false;
            _this.marker.map(function (item) {
                item.show();
            })
        },
        //修改网格文案
        changeMarker(j, type) {
            let _this = this;
            type = type ? type : 'normal'
            for (let i = 0; i < _this.marker.length; i++) {
                if (i == j) {
                    _this.marker[i].setLabel({
                        content: _this.marker[i].labelContent[type]
                    })
                } else {
                    _this.marker[i].setLabel({
                        content: _this.marker[i].labelContent.normal
                    })
                }
            }
        },
        //校验经度
        checkLng: function (lng) {
            let longrg = /^(\-|\+)?((1[0-7]\d)|([1-9]\d)|(\d))\.\d{4}(\d)+$/;
            if (!longrg.test(lng)) {
                return false;
            }
            return true;
        },
        //校验纬度
        checkLat: function (lat) {
            let latreg = /^(\-|\+)?(([1-8]\d)|(\d))\.\d{4}(\d)+$/;
            if (!latreg.test(lat)) {
                return false;
            }
            return true;
        },
        //轮播
        carousel() {
            let _this = this;
            let _len = _this.polygon.length;
            return {
                setIntervalFun() {
                    console.log('111')
                    _this.setIntervalParm.server_id = setInterval(function () {
                        //_this.changeGridStyles(_this.setIntervalParm.i,'active');
                        _this.changeMarker(_this.setIntervalParm.i, 'active');
                        _this.setIntervalParm.i++;
                        _this.setIntervalParm.i = _this.setIntervalParm.i < _len ? _this.setIntervalParm.i : 0;
                        //console.log(_this.setIntervalParm.server_id,'server_id');
                    }, 2000)
                },
                clearIntervalFun() {
                    clearInterval(_this.setIntervalParm.server_id);
                }
            }
        },
        //绘制图标
        drawFlag(arr, fun) {
            fun = fun || Function;
            let _this = this,_len = 0;
            if (arr.constructor == Array && arr.length > 0) {
                _this.map.remove(_this.textFlag);
                console.log(arr);
                for (let i = 0; _len = arr.length, i < _len; i++) {
                    this.addTextFlag(arr[i], i, fun);
                }

            } else {
                console.log("传入进去的数据格式不对")
            }

        },
        //添加标注
        addTextFlag(obj, i, fun) {
            let _this = this;
            if (!this.checkLng(obj.lng) || !this.checkLat(obj.lat)) {
                console.log('第' + (i + 1) + '个经纬度不符合规范，请检查'); return false;
            }
            let type = obj.type ? obj.type : 0;
            let unitType = obj.unitType ? obj.unitType : 0;
            // let path='./img/'+_this.textFlagIco[unitType][type];//静态资源情况下
            let path = require('../img/' + _this.textFlagIco[unitType][type]);

            let textFlagContent = {
                normal: '<div class="amap-flag amap-flag-normal"><div class="amap-flag-text">' + obj.label + '</div><div class="amap-flag-ico"><img src=' + path + ' /></div></div>',
                hover: '<div class="amap-flag amap-flag-hover"><div class="amap-flag-text">' + obj.label + '</div><div class="amap-flag-ico"><img src=' + path + ' /></div></div>',
                active: '<div class="amap-flag amap-flag-active"><div class="amap-flag-text">' + obj.label + '</div><div class="amap-flag-ico"><img src=' + path + ' /></div></div>',
            }
            let text = new AMap.Text({
                text: "<div class='text-flag-box'>" + textFlagContent.normal + "</div>",
                anchor: 'center', // 设置文本标记锚点
                cursor: 'pointer',
                style: {
                    background: 'none',
                    border: 'none',
                    color: "#fff",
                    height: '60px'
                },
                position: [obj.lng, obj.lat]
            });
            text.setMap(_this.map);
            text.textFlagContent = textFlagContent;
            _this.textFlag.push(text);
            text.on('click', function () {
                _this.changeTextFlag(i, 'active');
                fun(i);
            });
            text.on('mouseover', function () {
                _this.changeTextFlag(i, 'hover');
            });
            text.on('mouseout', function () {
                _this.changeTextFlag(i, 'normal');
            });
        },
        //修改标注
        changeTextFlag(j, type) {
            let _this = this;
            type = type ? type : 'normal';
            for (let i = 0; i < _this.textFlag.length; i++) {
                if (i == j) {
                    _this.textFlag[i].setText("<div class='text-flag-box'>" + _this.textFlag[i].textFlagContent[type] + "</div>")
                } else {
                    _this.textFlag[i].setText("<div class='text-flag-box'>" + _this.textFlag[i].textFlagContent.normal + "</div>")
                }
            }
        },
        //打开编辑框
        openInfo: function (information, position,callback) {
            let fun=callback||Function;
            let _this = this;
            let info = information ? information : '';
            _this.infoWindow = new AMap.InfoWindow({
                isCustom:_this.parms.isCustom,
                content: info.join("")  //使用默认信息窗体框样式，显示信息内容
            });
            _this.infoWindow.open(_this.map, [position.gps_lng, position.gps_lat]);
            _this.map.setCenter(new AMap.LngLat(position.gps_lng, position.gps_lat));
            // _this.map.setZoom(14);
            setTimeout(function(){
                fun();
            },1000);

        },
        //添加图标
        addPoint: function (arr=[], callback=()=>{}, callback02=()=>{}, noCluster=false) {
            let _this = this;
            _this.map.remove(_this.AutoPoint);
            _this.AutoPoint = [];
            _this.closeWindow();
            _this.clearcluster();
            if (Array.isArray(arr) && arr.length > 0) {
                let _len = arr.length
                for (let i = 0; i < _len; i++) {
                    if (_this.checkLng(arr[i].gps_lng) && _this.checkLat(arr[i].gps_lat)) {
                        _this.addPointIco(arr[i], i, callback);
                    } else {
                        // console.log('第' + (i + 1) + '数据经纬度有问题！')
                    }
                }
                //
                if (!noCluster) {
                    _this.addCluster(callback02);
                }else{
                    _this.map.add(_this.AutoPoint);
                }
            } else {
                console.log("传入进去的数据格式不对")
            }
            // setTimeout(()=>{
            //     _this.map.setFitView();
            //     debugger;
            // },1000)
            //  _this.map.zoomIn()
            // _this.map.setZoom(14)
        },
        befor(){

        },
        isSearch(area='中国'){
            let _this=this;
            let district = null;
            let polygons=[];

                //加载行政区划插件
            //实例化DistrictSearch
            let opts = {
                subdistrict: 0,   //获取边界不需要返回下级行政区
                extensions: 'all',  //返回行政区边界坐标组等具体信息
                level: 'district'  //查询行政级别为 市
            };
            district = new AMap.DistrictSearch(opts);
                //行政区查询
            _this.mappolygons=[];
            district.search(area, function(status, result) {
                let bounds = result.districtList[0].boundaries;
                if (bounds) {
                    for (let i = 0, l = bounds.length; i < l; i++) {
                        for(let j=0,h=bounds[i].length;j<h;j++){
                            _this.mappolygons.push([bounds[i][j].lng,bounds[i][j].lat])
                        }
                    }
                }
            });
        },
        isfanwei(point,path){
            return AMap.GeometryUtil.isPointInRing(point,path);//判断是不是在多边形内
        },
        after(){

        },
        //清空热地图
        clearHotMap(){
            // debugger;
            if(this.heatmap != null){
                this.heatmap.setMap(null);
            }
        },
        //添加热地图
        addHotMap(arr,type){
            let mytayle=type||0;
            let _this=this;
            this.clearHotMap();
            // this.clearAll();
            let getColor=_this.hotMapColor(mytayle);
            _this.map.plugin(["AMap.Heatmap"], function () {
                //初始化heatmap对象
                _this.heatmap = new AMap.Heatmap(_this.map, {
                    radius:60, //给定半径
                    opacity: [0, 0.7],
                    color: {
                        1: '#f0f9e8',
                        0.8: '#bae4bc',
                        0.6: '#7bccc4',
                        0.4: '#43a2ca',
                        0.2: '#0868ac',
                    },
                    // gradient:getColor.gradient

                });
                //设置数据集：该数据为北京部分“公园”数据
                _this.heatmap.setDataSet({
                    data: arr,
                    max: getColor.max
                });


            });
            // _this.map.setZoom(_this.map.getZoom()-2);
            _this.map.setFitView();
            _this.map.setZoom(_this.map.getZoom()-5);

           let center=_this.map.getCenter();

        //    _this.map.setZoom(_this.map.getZoom()+1);
        //    _this.map.setZoomAndCenter(center);
        },
        hotMapColor(_index){
         let  data=[
                {//全部
                    gradient:{
                        0.3: 'green',
                        0.6: 'yellow',
                        0.8: 'orange',
                        1.0: 'red'
                    },
                    max:210

                },
                {//火警
                    gradient:{
                        0: 'green',
                        0.3: 'yellow',
                        0.7: 'orange',
                        1.0: 'red'
                    },
                    max:10

                }
                ,
                {//异常
                    gradient:{
                        0.3: 'green',
                        0.6: 'yellow',
                        0.8: 'orange',
                        1.0: 'red'
                    },
                    max:100

                }
                ,
                {//其他
                    gradient:{
                        0.3: 'green',
                        0.6: 'yellow',
                        0.8: 'orange',
                        1.0: 'red'
                    },
                    max:100

                }
            ]
            return data[_index];
        },
        createWindowPop(component,item,fun=()=>{}){
            this.infoWindow = new AMap.InfoWindow({});
            this.infoWindow.setContent(component.$el)
            // this.maMap.openInfo([component.$el.innerHTML],item)
            this.infoWindow.open(this.map, [+item.gps_lng, +item.gps_lat]);
            this.map.setCenter(new AMap.LngLat(item.gps_lng, item.gps_lat));
            fun();
        },
        setCenter(item){
            console.log(item,'===item===')
            if(!item.gps_lng) return
            this.map.setCenter(new AMap.LngLat(item.gps_lng, item.gps_lat));
            this.map.setZoom(14)
        },
        addPointIco: function (obj, i, callback) {
            let _this = this;
            let iconName =  obj.iconName;
            let name = obj.device_name || obj.unit_name || obj.name;
            let text = new AMap.Text({
                // text: '<div class="map-point-name"><div class="map-point-text">' + name + '<div class="map-point-flag"><i class="ivu-icon ivu-icon-md-arrow-dropdown" style="font-size: 32px;"></i></div></div><span  id="'+obj.ID+'" title=' + name + ' class="objMarkers ' + obj.type.class + ' tb-flag icon anticon ' + iconName + '"></span></div>',
                text: `<div class="map-point-name status-point  ${_.get(obj,'className')}">
                            <div class="map-point-text" title="${name}">
                                <div class="map-point-flag">
                                     <div class="map-point-number">
                                        <div class="map-point-number-info">${_.get(obj,'deviceStatusCount.allCount')||0}</div>
                                    </div>    
                                     <span class="icon iconfont ${obj.iconName}"></span>
                                </div>
                            </div>
                         </div>`,
                anchor: 'center', // 设置文本标记锚点
                cursor: 'pointer',
                style: {
                    'color': _.get(obj,'color')||'#008aff',
                    'background': 'rgba(0,0,0,0)',
                    'border': 'none',
                    'padding': '0',
                },
                // offset:new AMap.Pixel(-29, -123),
                position: [parseFloat(obj.gps_lng), parseFloat(obj.gps_lat)]
            });
            //text.setMap(_this.map);
            text.on('click', function () {
                //_this.openInfo(obj,i);
                callback(obj, i);
            });
            text.object = obj;
            text.i = i;
            _this.AutoPoint.push(text);
        },
        //监听地图放大的级别
        monitorMapZoom(){
            this.map.on("zoomchange",()=>{
                if(this.map.getZoom()>16){
                    $(".map-point-name").addClass("active")
                }else{
                    $(".map-point-name").removeClass("active")
                }
            })
        },
        drawRoute: function (start, end, callback) {
            callback = callback || Function();
            let _this = this;
            let drivingOption = {
                map: _this.map,
                hideMarkers: false,
            }

            // 构造路线导航类
            let driving = new AMap.Driving(drivingOption)

            // 根据起终点经纬度规划驾车导航路线
            driving.search(new AMap.LngLat(start.lng, start.lat), new AMap.LngLat(end.lng, end.lat), function (status, result) {
                // result 即是对应的驾车导航信息，相关数据结构文档请参考  https://lbs.amap.com/api/javascript-api/reference/route-search#m_DrivingResult
                if (status === 'complete') {
                    callback
                } else {
                    log.error('获取驾车数据失败：' + result)
                }
            });
            _this.map.setFitView();
        },
        removePoint: function (callback) {
            let fun=callback||Function;
            let _this = this;
            _this.map.remove(_this.AutoPoint);
            _this.clearcluster();
            _this.map.setFitView();
            fun();
        },
        //绘制圆形范围
        drawArea: function (center, list, callback) {
            callback = callback || Function;
            let _this = this;
            let circle = new AMap.Circle({
                center: new AMap.LngLat(center.lng, center.lat),// 圆心位置
                radius: 2000, //半径
                strokeColor: "#1791fc", //线颜色
                strokeOpacity: 0.2, //线透明度
                strokeWeight: 3,    //线宽
                fillColor: "#1791fc", //填充色
                fillOpacity: 0.05//填充透明度
            });
            let list_data = [];
            for (let j = 0; j < list.length; j++) {
                let myObj = list[j];
                let myLngLat = new AMap.LngLat(myObj.gps_lng, myObj.gps_lat);
                if (circle.contains(myLngLat)) {//如果点在圆内则输出
                    list_data.push(list[j]);
                }

            }
            _this.addPoint(list_data, null, null, true);
            circle.setMap(_this.map);//显示圆圈
            _this.map.setFitView();//根据地图上添加的覆盖物分布情况，自动缩放地图到合适的视野级别
            _this.map.zoomIn()
        },
        //纯文本标记
        createText: function (obj) {
            con = obj.text ? obj.text : '';
            // 创建纯文本标记
            let text = new AMap.Text({
                text: con,
                anchor: 'center', // 设置文本标记锚点
                cursor: 'pointer',
                style: {
                    'padding': '10',
                    'margin-top': '-40px',
                    'border-width': 0,
                    'font-size': '12px',
                    'color': 'blue',
                    'background': '#008cff !important'
                },
                position: [obj.lng, obj.lat]
            });
            text.setMap(this.map);
        },
        //添加聚合
        addCluster: function (callback02) {
            let _this = this;
//             指定聚合后的点标记的图标样式，可缺省，缺省时为默认样式；

// 数据元素分别对应聚合量在1-10,11-100,101-1000…的聚合点的样式；
// https://lbs.amap.com/api/javascript-api/example/marker/markerclusterer/

            var count = _this.AutoPoint.length;
            let sts = [{
              url: "https://webapi.amap.com/theme/v1.3/m1.png",
              size: new AMap.Size(53, 53),
              offset: new AMap.Pixel(-16, -16)
          }, {
              url: "https://webapi.amap.com/theme/v1.3/m1.png",
                size: new AMap.Size(53, 53),
              offset: new AMap.Pixel(-16, -16)
          }, {
              url: "https://webapi.amap.com/theme/v1.3/m1.png",
               size: new AMap.Size(53, 53),
              offset: new AMap.Pixel(-18, -18)
          }];
        //   console.log( _this.AutoPoint,' _this.AutoPoint');
            _this.cluster = new AMap.MarkerClusterer(_this.map, _this.AutoPoint, {
                gridSize: 40,
                zoomOnClick: true,
                styles: sts,
                renderClusterMarker:function (context){
                    console.log(context,'====context===')
                    var div = document.createElement('div');
                    div.style.backgroundColor =_this.getClusterTextColor(context.markers||[]);
                    var size = 40;
                    div.style.width = div.style.height = size + 'px';
                    div.style.borderRadius='50%';
                    div.innerHTML = context.count;
                    div.style.lineHeight = size + 'px';
                    div.style.textAlign = 'center';
                    context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2));
                    context.marker.setContent(div)
                }
            });
            _this.cluster.on('click', function (data) {
                // debugger;
                let _data = [];
                if (data.markers) {
                    data.markers.map(function (item) {
                        _data.push(item.object);
                    });
                    // console.log(_data,'_data====')
                }
                // console.log(_data,'_data_data_data_data')
                callback02(_data);
            });
        },
        getClusterTextColor(markers){
            let totalOffline=0,totalAlarm=0;
            markers.map(item=>{
                if(_.get(item,'object.deviceStatus')==2){
                    totalAlarm=1
                }else if(_.get(item,'object.deviceStatus')==4){
                    totalOffline=1
                }
            })
            // console.log(arr,'我是生成的聚合点==')
            if(totalAlarm){
                return 'rgba(255, 0, 0,0.7)'
            }else if(totalOffline){
                return 'rgba(240, 150, 18, 0.7)'
            }else{
                return 'rgba(0,138,255,0.7)'
            }

        },
        //删除聚合
        clearcluster: function () {
            let _this = this;
            if (_this.cluster) {
                _this.cluster.setMap(null);
            }
        },
        //删除网格
        clearGrid() {

        },
        //清除所有的覆盖物
        clearAll: function () {
            let _this = this;
            _this.map.clearMap();
        },
        //关闭窗体
        closeWindow: function () {
            let _this = this;
            if (_this.infoWindow) {
                _this.infoWindow.close();
            }
        },
        drawAutoGrid(adcode){//地图自带插件绘制区域
            let _this=this;
            let map=this.map;
            //just some colors
            let colors = [
                "#3366cc", "#dc3912", "#ff9900", "#109618", "#990099", "#0099c6", "#dd4477", "#66aa00",
                "#b82e2e", "#316395", "#994499", "#22aa99", "#aaaa11", "#6633cc", "#e67300", "#8b0707",
                "#651067", "#329262", "#5574a6", "#3b3eac"
            ];

            AMapUI.loadUI(['geo/DistrictExplorer'], function(DistrictExplorer,$) {

                //创建一个实例

                let districtExplorer = new DistrictExplorer({
                    map: map,
                    eventSupport: true, //打开事件支持
                });
                switch2AreaNode(adcode);
                //切换区域
                function switch2AreaNode(adcode) {
                    districtExplorer.loadAreaNode(adcode, function(error, areaNode) {

                        //更新地图视野
                        map.setBounds(areaNode.getBounds(), null, null, true);

                        //清除已有的绘制内容
                        districtExplorer.clearFeaturePolygons();

                        //绘制子区域
                        districtExplorer.renderSubFeatures(areaNode, function(feature, i) {

                            let fillColor = colors[i % colors.length];
                            let strokeColor = colors[colors.length - 1 - i % colors.length];

                            return {
                                cursor: 'default',
                                bubble: true,
                                strokeColor: strokeColor, //线颜色
                                strokeOpacity: 1, //线透明度
                                strokeWeight: 1, //线宽
                                fillColor: fillColor, //填充色
                                fillOpacity: 0.35, //填充透明度
                            };
                        });

                        //绘制父区域
                        districtExplorer.renderParentFeature(areaNode, {
                            cursor: 'default',
                            bubble: true,
                            strokeColor: 'black', //线颜色
                            strokeOpacity: 1, //线透明度
                            strokeWeight: 1, //线宽
                            fillColor: null, //填充色
                            fillOpacity: 0.35, //填充透明度
                        });
                    });
                }


                //feature被点击
                districtExplorer.on('featureClick', function(e, feature) {
                    let props = feature.properties;
                    //如果存在子节点
                    // if (props.childrenNum > 0) {
                    //切换聚焦区域

                    switch2AreaNode(props.adcode);
                    // }
                });
            });
        },
        //绘制落点
        setPosition: function (obj, callback, zoom) {
            callback = callback || Function;
            let _this = this;
            _this.clearMarker();
            if (!this.checkLng(obj.lng) || !this.checkLat(obj.lat)) {

                console.log('该地址录入的经纬度不符合规范，请检查');
                //callback('该地址录入的经纬度不符合规范，请检查')
                return false;
            }

            _this.position_marker = new AMap.Marker({
                position: [parseFloat(obj.lng), parseFloat(obj.lat)],
                offset: new AMap.Pixel(-13, -30)
            });





            _this.position_marker.setMap(_this.map);
            if (zoom && /^[0-9]*[1-9][0-9]*$/.test(zoom)) {
                _this.map.setZoomAndCenter(zoom, [parseFloat(obj.lng), parseFloat(obj.lat)]);
            } else {
                _this.map.setFitView();
                _this.map.zoomIn()
            }

            _this.map.setFitView();
        },
        // 清除 marker
        clearMarker: function () {
            let _this = this;
            if (_this.position_marker&&_this.position_marker.setMap) {
                _this.position_marker.setMap(null);
                _this.position_marker = null;
            }
        },
        //计算区域的中心点
        getAreaCenter: function (lnglatarr) {
            //二维数组选取第一个计算中心
            lnglatarr = lnglatarr[0].lng ? lnglatarr : lnglatarr[0]
            let total = lnglatarr.length;
            let X = 0, Y = 0, Z = 0;

            for (let i = 0; i < total; i++) {
                let lng = lnglatarr[i].lng * Math.PI / 180;
                let lat = lnglatarr[i].lat * Math.PI / 180;
                let x, y, z;
                x = Math.cos(lat) * Math.cos(lng);
                y = Math.cos(lat) * Math.sin(lng);
                z = Math.sin(lat);
                X += x;
                Y += y;
                Z += z;
            }
            X = X / total;
            Y = Y / total;
            Z = Z / total;
            let Lng = Math.atan2(Y, X);
            let Hyp = Math.sqrt(X * X + Y * Y);
            let Lat = Math.atan2(Z, Hyp);
            return {
                lng: Lng * 180 / Math.PI,
                lat: Lat * 180 / Math.PI
            }
        }
    }
})();
